package com.yjc.blog.controller;


import com.yjc.blog.domain.bo.CateSave;
import com.yjc.blog.domain.bo.ECategoryDao;
import com.yjc.blog.domain.vo.CategoryVO;
import com.yjc.blog.domain.vo.PageVO;
import com.yjc.blog.service.ICategoryService;
import com.yjc.blog.utils.R;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类 前端控制器
 * </p>
 *
 * @author yjc
 * @since 2024-10-30
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private ICategoryService categoryService;

    @GetMapping("/list")
    public R<PageVO<CategoryVO>> list(@Valid ECategoryDao dao){
        R<PageVO<CategoryVO>> r = new R<>();
        PageVO<CategoryVO> list = categoryService.CateList(dao);
        r.setContent(list);
        return r;
    }
    @PostMapping("/save")
    public R save(@RequestBody CateSave save){
        categoryService.CateSave(save);
        return new R();
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        categoryService.cateDelete(id);
        return new R();
    }
    @GetMapping("/all")
    public R<List<CategoryVO>> all(){
        List<CategoryVO> list = categoryService.all();
        R<List<CategoryVO>> r = new R<>();
        r.setContent(list);
        return r;
    }
}
